﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace WeatherCN_Phone
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
            if (App.ViewModel.WeatherInfo.cityid == null)
            {
                App.ViewModel.GetlocalCityName();
            }
            else
            {
                ;
            }
        }

        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (App.ViewModel.selectIndex.HasValue)
            {
                this.Panorama_Main.DefaultItem = this.Panorama_Main.Items[App.ViewModel.selectIndex.Value];
            }

        }

        private void LongListSelectionChanged(object sender, RoutedEventArgs e)
        {
            Panorama_Main.DefaultItem = Panorama_Main.Items[0];
        }

        private void MenuItem_DelFavClick(object sender, RoutedEventArgs e)
        {
            ((MainViewModel)DataContext).DelFavCommand.Execute((sender as MenuItem).Tag.ToString());
        }
        //更改标识收藏的城市或地区的颜色
        private void MenuItem_ChangeFavColorClick(object sender, RoutedEventArgs e)
        {
            ((MainViewModel)DataContext).SetFavoriteColorCommand.Execute((sender as MenuItem).Tag.ToString());
        }

        private void MenuItem_GetWeatherInfoClick(object sender, RoutedEventArgs e)
        {
            ((MainViewModel)DataContext).GetSpecificWeatherInfoCommand.Execute((sender as MenuItem).Tag);
            Panorama_Main.DefaultItem = Panorama_Main.Items[0];
        }

        private void Panorama_Main_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((MainViewModel)DataContext).SetCurrentPanoramaItemNameCommand.Execute(this.Panorama_Main.SelectedIndex); ;
        }
    }
}